<?php
	class hinhanhdb
	{
		public function Add($TenHinhAnh, $MaSanPham, $patch)
		{
			$sql = "INSERT INTO `tbl_hinhanh`(`TenHinhAnh`, `MaSanPham`, `patch`) 
			VALUES ('$TenHinhAnh', $MaSanPham, '$patch')";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Delete($MaSanPham)
		{
			$sql = "DELETE FROM `tbl_hinhanh` WHERE MaSanPham = '$MaSanPham' ";
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
		
		public function Update($MaHinhAnh, $TenHinhAnh, $patch)
		{
			$sql = "UPDATE `tbl_hinhanh` SET TenHinhAnh='$TenHinhAnh', patch='$patch' WHERE MaHinhAnh = '$MaHinhAnh'"; 
			$data = new dataservice();
			return $data->ExecuteNonQuery($sql);
		}
	
		public function GetList($MaHinhAnh, $TenHinhAnh, $MaSanPham)
		{
			$sql = " SELECT * FROM `tbl_hinhanh`, `tbl_sanpham` WHERE tbl_hinhanh.MaSanPham=tbl_sanpham.MaSanPham ";
			if($MaHinhAnh!="")
				$sql .= " AND tbl_hinhanh.MaHinhAnh = '$MaHinhAnh' ";
			if($TenHinhAnh!="")
				$sql .= " AND tbl_hinhanh.TenHinhAnh LIKE '%$TenHinhAnh%' ";
			if($MaSanPham!="")
				$sql .= " AND tbl_hinhanh.MaSanPham = $MaSanPham ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
		public function Find($MaHinhAnh, $TenHinhAnh)
		{
			$sql = "SELECT * FROM `tbl_hinhanh`, `tbl_sanpham` WHERE tbl_hinhanh.MaSanPham=tbl_sanpham.MaSanPham ";
			if($MaHinhAnh!="" || $TenHinhAnh!="")
				$sql = " SELECT * FROM `tbl_hinhanh` WHERE tbl_hinhanh.MaHinhAnh = '$MaHinhAnh' OR tbl_hinhanh.TenHinhAnh LIKE '%$TenHinhAnh%' OR tbl_hinhanh.MaSanPham = $MaSanPham ";
			$data = new dataservice();
			return $data->ExecuteQuery($sql);
		}
	}
?>